package com.ychug.gateway.system;

import com.sun.org.apache.regexp.internal.RE;

import com.ychug.common.base.ResultAjaxHash;
import com.ychug.framework.web.base.BaseController;
import com.ychug.framework.web.page.TableDataInfo;
import com.ychug.service.system.entity.SysNoticeEntity;
import com.ychug.service.system.service.ISysNoticeService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公告 信息操作处理
 * 
 * @author dds
 */
@Controller
@RequestMapping("/sys/notice")
public class SysNoticeController extends BaseController
{
    private String prefix = "modules/sys/notice";

    @Autowired
    private ISysNoticeService noticeService;


    @GetMapping()
    public String notice()
    {
        return prefix + "/viewNotice";
    }

    /**
     * 查询公告列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysNoticeEntity notice)
    {
        startPage();
        List<SysNoticeEntity> list = noticeService.selectNoticeList(notice);
        return getDataTable(list);
    }

    /**
     * 新增公告
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/addNotice";
    }

    /**
     * 新增保存公告
     */

    @PostMapping("/add")
    @ResponseBody
    public ResultAjaxHash addSave(SysNoticeEntity notice)
    {
        notice.setCreateBy("admin");
        return toAjax(noticeService.insertNotice(notice));
    }

    /**
     * 修改公告
     */
    @GetMapping("/edit/{noticeId}")
    public String edit(@PathVariable("noticeId") Long noticeId, ModelMap mmap)
    {
        mmap.put("notice", noticeService.selectNoticeById(noticeId));
        return prefix + "/editNotice";
    }

    /**
     * 修改保存公告
     */

    @PostMapping("/edit")
    @ResponseBody
    public ResultAjaxHash editSave(SysNoticeEntity notice)
    {
        notice.setUpdateBy("admin");
        return toAjax(noticeService.updateNotice(notice));
    }

    /**
     * 删除公告
     */

    @PostMapping("/remove")
    @ResponseBody
    public ResultAjaxHash remove(String ids)
    {
        return toAjax(noticeService.deleteNoticeByIds(ids));
    }
}
